package com.dev.utils.app;

import ohos.agp.colors.RgbColor;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;

public class ShapeUtils {
    private final ShapeElement mDrawable;

    /**
     * 构造函数
     */
    private ShapeUtils() {
        this(new ShapeElement());
    }

    public ShapeElement getmDrawable() {
        return mDrawable;
    }

    /**
     * 构造函数
     * @param drawable {@link ShapeElement}
     */
    private ShapeUtils(ShapeElement drawable) {
        if (drawable == null) drawable = new ShapeElement();
        this.mDrawable = drawable;
    }


    /**
     * 创建圆角 Shape
     * @param radius 圆角值
     * @param color  背景色
     * @return {@link ShapeUtils}
     */
    public static ShapeUtils newShape(
            final float radius,
             final int color
    ) {
        return new ShapeUtils().setCornerRadius(radius).setColor(color);
    }
    /**
     * 设置圆角
     * @param radius 圆角值
     * @return {@link ShapeUtils}
     */
    public ShapeUtils setCornerRadius(final float radius) {
        if (mDrawable != null) mDrawable.setCornerRadius(radius);
        return this;
    }

    /**
     * 设置背景填充颜色
     * @param argb 背景色
     * @return {@link ShapeUtils}
     */
    public ShapeUtils setColor(final int argb) {
        if (mDrawable != null) mDrawable.setRgbColor(RgbColor.fromArgbInt(argb));
        return this;
    }

}
